package org.lanqiao.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.lanqiao.entity.Bill;
import org.lanqiao.service.BillItemService;
import org.lanqiao.service.BillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/bill")
public class BillItemControler {
	@Autowired
	BillItemService billItemService;
	@RequestMapping("/bill_item")
	/*public ModelAndView listBill(int curPage) {
    	int pageSize = 4;//自定义每页显示的个数
    	int count = billItemService.count();//表中总记录数，从数据库查的
	    int pageCount = (count%pageSize==0)?(count/pageSize):(count/pageSize+1);//总页数，算的
	    int start = (curPage-1)*pageSize;//起始记录行数
	    List<Bill> list = billItemService.selectAllBillItem(start,pageSize);
	    ModelAndView mav = new ModelAndView("");
		mav.addObject("bills", list);
		mav.setViewName("bill_list");
		return mav;
	} */
	public ModelAndView ItemBill(HttpServletRequest request,Bill bill) {
		int pageSize  =  5;//每页显示页数
		int currentPage = -1;//当前页数
		int count = billItemService.count();//表中总记录数
		String curPage = request.getParameter("currentPage");//获取当前页数
		if(curPage==null)
			currentPage=1;
		else
			currentPage=Integer.parseInt(curPage);  
		int pageCount = (count%pageSize==0)?(count/pageSize):(count/pageSize+1);
		int start = (currentPage-1)*pageSize;//起始记录行数
		List<Bill> list = billItemService.selectAllBillItem(start,pageSize,bill);
		request.setAttribute("totalRecord", count);
        request.setAttribute("pageSize", pageSize);
        request.setAttribute("currentPage", currentPage);
        request.setAttribute("pageCount", pageCount);
        request.setAttribute("a", start);
	    ModelAndView mav = new ModelAndView("bill/bill_item");
		mav.addObject("bills", list);
		return mav;
	}
}
